﻿using System;

namespace StackExchange.Redis.Extensions.MQ
{
    internal class MessageQueueHeartbeat : IDisposable
    {
        private IDatabase _redisDb;
        private System.Timers.Timer _timer;
        private string _mqName;
        private string _message;

        public MessageQueueHeartbeat(IDatabase redisDb, string mqName, string message)
        {
            _redisDb = redisDb;
            _mqName = mqName;
            _message = message;
            _timer = new System.Timers.Timer();
            _timer.Interval = TimeSpan.FromSeconds(3).TotalMilliseconds;
            _timer.AutoReset = true;
            _timer.Elapsed += _timer_Elapsed;
            _timer.Start();
        }

        private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //Nothing to do
        }

        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _timer.Stop();
                    _timer.Dispose();
                }

                disposedValue = true;
            }
        }

        public void Dispose()
        {
            Dispose(true);
        }
    }
}
